package Elemenets;

import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;

import util.GetDevice;
import util.UIHelper;
import java.util.ArrayList;
import java.util.List;

import static util.GetDevice.getDevice;

/**
 * Created by zhe.xiao on 2017/7/24.
 */

public class PushElements {
    private static PushElements pushElements;
    private UiDevice device = getDevice();
    private PushElements(){}
    public static PushElements getInstance(){
        if(pushElements == null){
            pushElements = new PushElements();
        }
        return pushElements;
    }

    /**
     * 获取消息中心的服务通知
     * @return
     */
    public UiObject2 getServerMess() {
        UiObject2 u2 = null;
        u2 = device.wait(Until.findObject(By.text("服务通知")), 20000);
        return u2;
    }

    /**
     * 获取消息中心的对话消息
     * @return
     */
    public UiObject2 getMess(){
        UiObject2 u2 = null;
        u2 = device.wait(Until.findObject(By.text("对话消息")), 20000);
        return u2;
    }

    public UiObject2 getList(){
        UiObject2 ui = null;
        UIHelper.getElementsAction().sleep(5000);
        ui = device.findObject(By.res("android:id/list"));
        return ui;
    }
    public List<UiObject2> getElementList(){
        List<UiObject2> l = new ArrayList<UiObject2>();
        UIHelper.getElementsAction().sleep(5000);
        l = device.findObjects(By.res("com.mqunar.atom.im:id/atom_im_name"));
        for(UiObject2 o: l){
            if(o.getText().isEmpty()){
                l.remove(o);
            }
        }
        return l;
    }
}
